#include "stdafx.h"
#include "Gun.h"

void CGun::Update(float fDeltaTime)
{
	//Shot Timer
	if(!m_bShootable)
	{
		m_fShotTimer -= fDeltaTime;
		if(m_fShotTimer <= 0.0f)
		{
			m_fShotTimer = 0.5f;
			m_bShootable = true;
		}
	}

	//Energy Regen
	if(m_nEnergy < 100)
	{
		//Check Regen rate
		m_fEnergyRegenTimer -= fDeltaTime;
		if(m_fEnergyRegenTimer <= 0.0f)
		{
			m_fEnergyRegenTimer = 1.0f;
			m_nEnergy += 7;
			if(m_nEnergy > 100)
			{
				m_nEnergy = 100;
			}
		}
	}
}

void CGun::Init()
{
	m_fShotTimer = 0.5f;
	m_bShootable = false;
	m_fEnergyRegenTimer = 1.0f;
	m_nEnergy = 100;
}

bool CGun::Shoot()
{
	if(m_nEnergy >= 10)
	{
		if(m_bShootable)
		{
			m_nEnergy -= 10;
			m_bShootable = false;
			return true;
		}
	}

	return false;
}